package org.wiztools.commons.feed;

import java.io.IOException;
import java.io.InputStream;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;

/**
 *
 * @author subhash
 */
class WrappedHttpClientInputStream extends InputStream {

    private HttpResponse response;
    private HttpClient client;
    private InputStream is;

    WrappedHttpClientInputStream(HttpResponse response, HttpClient client) throws IOException{
        this.response = response;
        this.client = client;
        is = response.getEntity().getContent();
    }

    @Override
    public int read() throws IOException {
        return is.read();
    }

    @Override
    public int read(byte b[], int off, int len) throws IOException{
        return is.read(b, off, len);
    }

    @Override
    public void close() throws IOException{
        response.getEntity().consumeContent();
        client.getConnectionManager().shutdown();
        super.close();
    }

}
